<?php
namespace app\test\controller;
use think\Controller;
class Index extends Base
{
    public function index()
    {   
        return $this->fetch();
    }  

    public function api(){
      $data = model('Stu')->where('name','wjs')
                          ->find();
            return json_encode($data);
    } 
    
    public function pwdLogin($username,$password)
     {
     	$username = $_GET['username'];
     	$password = $_GET['password'];
     	$info = model('Member')->where("username='{$username}' and password='{$password}'")->find();
       //	return json_encode($info);
     	if ($info) {
     		$data['token']= $this->create_token();
     		$data['mid']= $info['id'];
     		$count = model('Token')->where("mid={$data['mid']}")->count();

     		if ($count>0) {
     			model('Token')->where("mid={$data['mid']}")->update(array('token'=>$data['token']));
     		}else{
               model('Token')->insertGetId($data);
     		}
     		$info['token']=$data['token'];
     		ajaxmsg('登录成功',1,$info);
     	}else{
     		ajaxmsg('用户名字或者密码错误,请重新提交',0);
     	}

     }

}
